#!/bin/bash

# Name:     Veress Botond
# Group:    521/3
# Date:     2012.04.05
# Exercise: 4.; labor04 - grep
# 4. Írassa ki a paraméterként megadott csoport, és az ehhez a csoporthoz tartozó
#    felhasználók (civil) nevét. (lásd /etc/group, illetve /etc/passwd állományok)

# Checking the parameter count
if [ $# -eq 1 ]; then
	# Finding the corresponding group data line
	data=`grep "^.*:.*:$1:" /etc/group`
	if [ "$data" != "" ]; then
		# Get the name of the group
		group=`cut -d ":" -f 1 <<< "$data"` 
		echo The name of the group is: $group
		# Get the name of the members of the group
		name=`grep ".*:.*:[0-9]*:$1:" /etc/passwd | cut -d ":" -f 5`
		if [ "$name" != "" ]; then
			echo "Member(s) of the group: $name"
		else
			echo There are no users in this group!
		fi
	else
		echo The group with the ID \"$group\" does not exist!
	fi
else
	echo Usage: $0 group
	echo You shall pass 1 parameter	!
fi

if [ $# -eq 0 ]; then
	echo "HULYE";
else
	echo "Nem eg
fi
